#include"../common.h"
int bltNum=0;
int indexnum=0;
BuiltinCmd blt[MAX_BUILTIN_FUNC_NUM];
extern obj_index _index;
extern obj_index indexs[MAX_REFS_HEADS_NUMS];
extern char buf[80];
extern char _obj[MAX_BUILTIN_DESC_LENGTH];
extern char _GIT[MAX_BUILTIN_DESC_LENGTH];
extern char txt_index[MAX_BUILTIN_DESC_LENGTH];

int initBuiltin() {
    git_add();
    git_init();
    git_commit();
    git_rm();
    git_diff();
    git_pwd();
    git_log();
    return 0;
}
int addBuiltinCmd(const BuiltinCmd * cmd) {
    memcpy(blt + bltNum, cmd, sizeof(BuiltinCmd));
    bltNum ++;
    return 0;
}
/** 查找名称为 name 的内置命令 */
int findBuiltinCmd(const char * name) {
    int i;
    for(i = 0; i < bltNum; i++){
		if(strcmp(name, blt[i].name) == 0) return i;
    }
	return -1;
}
/*
int findtxt(const char * name,obj_index *u,char *SHA_1,char *obj_sha) {
    if (strcmp(u->file_type,"root")){
		return findtxt(name,u->file_son,SHA_1,obj_sha);
	}
	for (obj_index *p=u;p;p=p->file_next){
    	if (strcmp(p->file_path,name)==0){
    	    strcpy(p->file_type,"blob");
    	    strcpy(p->tree,SHA_1);
    	    strcpy(p->file_sha_path,obj_sha);
			return 1;	
		}
		else return findtxt(name,u->file_son,SHA_1,obj_sha);
	}
	return 0;
}
*/

int findtxt(const char * name,obj_index _index,char *SHA_1,char *obj_sha){
	FILE *fp=fopen(txt_index,"r");
	obj_index _INDEX;
	int pos=0;indexnum=0;
	while(fread(&_INDEX,sizeof(_INDEX),1,fp)){
		indexs[++indexnum]=_INDEX;
		if (strcmp(name,_INDEX.file_path)==0) pos=indexnum;
	}
    fclose(fp);
    if (!pos) indexs[++indexnum]=_index;
	return pos;
}




